<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>绘制文字</title>
</head>
<body>
  <canvas id="test" width="800" height="400" style="background: #eee;"></canvas>

  <script>
    /** @type {HTMLCanvasElement} */
    const canvas = document.getElementById('test')
    const context = canvas.getContext('2d')

    context.moveTo(0, 30)
    context.lineTo(100, 30)
    context.stroke()

    // 绘制文字
    context.font = '30px 仿宋'
    context.textAlign = 'center'
    context.fillText('123', 100, 30)
  </script>
</body>
</html>